//
//  CustomTextField.m
//  sqliteToEnity
//
//  Created by hament on 13-8-14.
//  Copyright (c) 2013年 hament. All rights reserved.
//

#import "CustomTextField.h"

@implementation CustomTextField

-(void)awakeFromNib{
     [self setWantsLayer:YES];
    
    int opts = (NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways);
    NSTrackingArea *trackingArea = [[NSTrackingArea alloc] initWithRect:NSMakeRect(0, 0, self.frame.size.width, self.frame.size.height) options:opts owner:self userInfo:nil];
    
    NSLog(@"frame:%@",NSStringFromRect(self.frame));
    [self addTrackingArea:trackingArea];
}

- (void)drawRect:(NSRect)drawRect
{

    
    [super drawRect: drawRect];
    
}


-(void)mouseEntered:(NSEvent *)theEvent{
    
    CALayer *lay = [self layer];
    CGColorRef  myColor=CGColorCreateGenericRGB(1, 0, 0, 1);
    [lay setBorderColor:myColor];
    [lay setBorderWidth:2];
   
    [self setLayer:lay];
    [self makeBackingLayer];
    //CGColorRelease(myColor);
}

-(void)mouseExited:(NSEvent *)theEvent{
    
    CALayer *lay = [self layer];
    CGColorRef  myColor=CGColorCreateGenericRGB(1, 0, 0, 1);
    [lay setBorderColor:myColor];
    [lay setBorderWidth:0];
//    [self setWantsLayer:YES];
    [self setLayer:lay];
    [self makeBackingLayer];
    //CGColorRelease(myColor);
}



//-(void)updateTrackingAreas{
//    [super updateTrackingAreas];
//    if (self.trackingArea){
//        [self removeTrackingArea:self.trackingArea];
//        
//    }
//    
//    NSTrackingAreaOptions options = NSTrackingInVisibleRect | NSTrackingMouseEnteredAndExited | NSTrackingActiveInKeyWindow;
//    self.trackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRect options:options owner:self userInfo:nil];
//    [self addTrackingArea:self.trackingArea];
//    
//}


@end
